package com.example.application1.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.application1.Adapter.newsTabViewPagerAdapter;
import com.example.application1.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;


public class service_Fragments extends Fragment {
    private TabLayout tabLayout4;
    private ViewPager viewpager4;
    private List<Fragment> fragments;
    private View view;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.service_fragments, container, false);
        initView();
        initToolbar();
        return view;
    }

    private void initToolbar() {
        Toolbar toolbar = view.findViewById(R.id.my_toolbar);
        toolbar.setTitle("");
        TextView toolbar_title = view.findViewById(R.id.toolbar_title);
        toolbar_title.setText("服务中心");
    }

    private void initView() {
        fragments=new ArrayList<>();
        tabLayout4=view.findViewById(R.id.tabLayout4);
        viewpager4=view.findViewById(R.id.viewpager4);

        fragments.add(weatherFragment.newInstance());
        fragments.add(festivalFragment.newInstance());


        String[] titles={"天气查询","节假日","天气查询1","疫情防控","银行汇率"};
        viewpager4.setAdapter(new newsTabViewPagerAdapter(getChildFragmentManager(),fragments,titles));
        tabLayout4.setupWithViewPager(viewpager4);

    }

}
